package com.woniuxy.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: ideaAdmin
 * TODO:对controller层 没有捕获的异常进行处理
 * Date: 2022/2/11:17:57
 * Description:
 */
//@Component
public class MyExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
                                         Object handler, Exception exception) {
        ModelAndView modelAndView = new ModelAndView();
        MyException myException;
        if (exception instanceof MyException) {
            myException = (MyException) exception;
            modelAndView.addObject("msg",exception.getMessage());
        }
        modelAndView.setViewName("ok");
        return modelAndView;
    }
}
